package samsung.other;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import samsung.exceptions.WrongCountriesNumberException;

/**
 * Class realized methods for reading information from console.
 *
 * @author Vitaliy Muzalevskiy
 */
public class Reader {
    
    /**
     * Method for reading from console information about number of countries
     * in area.
     *
     * @return <code>int</code> value of countries number.
     * @throws NumberFormatException if entered value was non integer number.
     * @throws WrongCountriesNumberException if entered number don`t satisfy 
     *      defined limits.
     */
    public int readCountriesNumber() 
            throws NumberFormatException, WrongCountriesNumberException {
        int result = 0;
        String value;
        BufferedReader reader;
        System.out.println("Enter countries number in current area "
                + "(enter 0 to complete):");
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            value = reader.readLine();
            result = Integer.parseInt(value);
            if (result < Controller.MIN_COUNTRY_NUMBER 
                    || result > Controller.MAX_COUNTRY_NUMBER){
                throw new WrongCountriesNumberException();
            }
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
    /**
     * Method for reading from console information about country.
     * @return <code>String</code> value with entered information.
     */
    public String readCountryInfo() {
        String result = null;
        BufferedReader reader;
        System.out.println("Enter information about country:");
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
            result = reader.readLine();
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        return result;
    }
    
}
